/**
 * Package	: com.coship.adstorm.webservice.advertise
 * File		: InitDispplayReq.java
 * Company 	: Shenzhen Coship Electronics CO., LTD.
 * Version  : v1.0
 * Description 	: <Detail Description for package>
 *
 * Copyright (c) 2003-2009 Shenzhen Coship Electronics CO., LTD.
 * Rainbow Bldg.,North,Hi-Tech Industrial Park,Nanshan District,Shenzhen,China,P.C.518057.
 * All rights reserved.
 * The contents of this file are confidential and proprietary to COSHIP.
 * Copying is explicitly prohibited without the express permission of COSHIP.
 *
 * Create Date	: May 4, 2010
 * Create By    : 904147
 * History :$
 */
package com.coship.vasms.adstorm.webservice.advertise;

import java.io.Serializable;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger;

import com.coship.vasms.adstorm.common.BeanHelper;
import com.coship.vasms.adstorm.common.CommonUtils;
import com.coship.vasms.adstorm.common.DateHelper;
import com.coship.vasms.adstorm.service.ArrangeNotifyService;

/** 
 * 
 * File Name    : InitDispplayReq.java
 * @Description 	: <Detail Description for Class >
 * @author 904147
 */
public class InitDisplayReq implements Serializable {

	/**
	 * Description 	: <Detail Description for package>
	 * Author       : 904147
	 */
	private static final long serialVersionUID = 1L;
	
	private static Logger logger = Logger
		.getLogger(InitPlayReq.class);
	public static Configuration configuration;
	public static String FILE_NAME = "adnotifydisplay.properties";
	public ArrangeNotifyService arrangeNotifyService = null;
	public Integer pageNo = 1;
	public Integer pageSize;
	public Integer pages = 1;
	
	/**
	 * 
	 * Description 	: ���������ļ�����ȡConfiguration����
	 *
	 * @return
	 *
	 */
	static{
		try {
			configuration = new PropertiesConfiguration(CommonUtils
					.getConfigPath()
					+ CommonUtils.getSysFileSeparator()
					+ FILE_NAME);
			if (configuration == null) {
				logger.error("ϵͳ�����ļ�" + FILE_NAME + "������!");
				throw new IllegalArgumentException("ϵͳ�����ļ�"
						+ FILE_NAME + "������!");
			}
		} catch (ConfigurationException e) {
			logger.error("�������ļ�" + FILE_NAME + "���ִ���");
			throw new IllegalArgumentException("�������ļ�" + 
					FILE_NAME + "���ִ���");
		}
	}
	
	public void init(){
		pageSize  = Integer.valueOf((String)configuration
			.getProperty("adstorm.webpage.pageSize"));
		//��ȡ��������
		Integer n = Integer
			.valueOf((String)configuration.getProperty("advertise.notify.display.stop.endtime"));
		String time = DateHelper.getDate(n);
		arrangeNotifyService = (ArrangeNotifyService)BeanHelper
			.getInstance().getBean("arrangeNotifyService");
		Integer count = arrangeNotifyService.countPlay(time);
		if(count != null && count > 0){
			pages = (count - 1)/pageSize + 1;
		}
	}
	
	public Integer getPageStart(Integer pageNo){
		if(pageNo == 1)
			return 0;
		else
			return pageSize*(pageNo-1);
	}

}
